template.defaults.imports.CountdownTime = function (factEndDate) {
    var timestamp = (new Date()).valueOf();
    return factEndDate - timestamp;
};


    var loading = false; //状态标记
    var hasNextPage = false;
    var pageNo = 1;
   
    queryList(pageNo);

    //下拉刷新
    $("#aroundBox").pullToRefresh().on("pull-to-refresh", function () {
        $('#left-list-content').html("");
        $('#right-list-content').html("");
        pageNo = 1;
        queryList(pageNo,function(){
            $("#aroundBox").pullToRefreshDone(); // 重置下拉刷新
        });
    });
  
    //上拉加载更多
    $('#aroundBox').infinite().on("infinite", function () {
        if (hasNextPage){
            pageNo++;
            queryList(pageNo,function(){
            },true);
        }        
    });

    function queryList(pageNo,callback,isMore){
        if (loading) return;
        loading = true;
        var params = {};
        params.start = (pageNo - 1) * 20;
        params.limit = 20;
         /* global getCookie */
         /* global auctionId */
         params.token = getCookie("token");
         params.auctionId = auctionId;     
        $.get('/antique/api/mallProduct/manage/query_list', params, function (result) {
            if (result.code == 0) {
                var leftList = [];
                var rightList = [];
                if(result.data.list){
                    for(var i = 0;i<result.data.list.length;i++){
                        if(i%2 == 0){
                            leftList.push(result.data.list[i]);
                        } else {                        
                            rightList.push(result.data.list[i]);
                        }
                    }
                }
                if (!isMore) {
                    /* global template */
                    document.getElementById('left-list-content').innerHTML = template('left-list', {list:leftList});
                    document.getElementById('right-list-content').innerHTML = template('right-list', {list:rightList});
                } else {
                    $('#left-list-content').append(template('left-list', {list:leftList}));
                    $('#right-list-content').append(template('right-list', {list:rightList}));
                }
                hasNextPage = result.data.hasNextPage;
                if (!result.data.hasNextPage) {
                    $('#loadmore').hide();
                    $('#nomore').show();
                } else {
                    $('#loadmore').show();
                    $('#nomore').hide();
                }
                if (callback) callback();
                loading = false;
            }            
        });
    }

    function delPro (proId) {
        $.confirm("您是否确认删除？删除后将不可恢复", "", function() {
            $.post('/antique/api/mallProduct/manage/delete_product', { id:proId,token:getCookie('token') }, function (result) {
                if (result.code == 0) {
                    $.toast("操作成功！");
                    $("#contentTo").html("");
                    pageNo = 1;
                    queryList(pageNo,function(){},true);
                } else {
                 $.toast(result.message, "cancel");
                }
             });
          }, function() {
            //取消操作
          });
        
    }

